package org.dna.opdracht1;

import java.util.Random;

public class RandomTwo extends RandomPerm {

	public RandomTwo(String name) {
		super(name);
	}

	// T(N) = O(F(2^N))
	@Override
	protected int[] randomPerm(int n) {
		int[] array = new int[n]; // 1 statement
		boolean[] used = new boolean[n]; // 1 statement

		Random random = new Random(); // 1 statement
		array[0] = random.nextInt(n); // 1 statement
		used[array[0]] = true; // 1 statement

		for (int i = 1; i < n; i++) { // n iterators
			int number = random.nextInt(n);  // 1 statement

			if(used[number]) { // 1 statement
				i--; // 1 statement
			} else {
				array[i] = number; // 1 statement
			}
			used[number] = true; // 1 statement
		}
		return array;
	}
}
